import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/model/pay_model/list_bank_branch_hf_model.dart';
import 'package:yysk_app/model/pay_model/list_bank_hf_model.dart';
import 'package:yysk_app/net/api/pay_url.dart';
import 'package:yysk_app/net/http.dart';
import 'package:yysk_app/utils/js_tool.dart';

class SelectBankListBranchController extends GetxController {
  var nameController = TextEditingController();
  var banks = RxList<ListBankBranchHfModel>([]);
  var filteredBanks = RxList<ListBankBranchHfModel>([]);
  var type = 'add'.obs; //add 添加 ，withdraw 提现 ，order 订单
  var bankCode = ''.obs;
  // var keyword = ''.obs;
  @override
  void onInit() {
    super.onInit();
    type.value = Get.parameters['type'] ?? Get.arguments['type'];
    bankCode.value = Get.parameters['bankCode'] ?? Get.arguments['bankCode'];
    // getBankList();
    nameController.addListener(() {
      if (nameController.text.length >= 2) {
        getBankList();
      }
    });
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    nameController.dispose();
  }
  // 银行卡列表

  Future<void> getBankList() async {
    http.netFetch<List<ListBankBranchHfModel>>(
      PayUrl.listBranchBank,
      params: {
        "channel": "HUIFU",
        "bankCode": bankCode.value,
        'keyword': nameController.text,
      },
      method: Method.post,

      success: (r) {
        banks.clear();
        filteredBanks.clear();
        banks.addAll(r.data ?? []);
        filteredBanks.addAll(r.data ?? []);
        return r;
      },
    );
  }
}
